from parameterized import parameterized

from Finance_fun.base.get_driver import GetDriver
from Finance_fun.page.page02_login import PageLogin
from Finance_fun.tool import assert_rl
from Finance_fun.tool.read_json import read_json
import unittest
from selenium import webdriver


def get_login_data():
    case = read_json("data02_login_case.json")
    list_null = []
    for data in case.values():
        list_null.append(
            (
                data["phone"],
                data["password"],
                data["expect"]
            )
        )
    return list_null

# print(get_login_data())

class LoginTest(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
       cls.driver = GetDriver.get_driver()
       cls.login = PageLogin(cls.driver)
       cls.login.page_click_login_link()

    @classmethod
    def tearDown(self):
        GetDriver.quit_driver()

    @parameterized.expand(get_login_data())
    def test_login(self,phone,password,expect):
        self.login.page_login(phone, password)
        if expect in "登录成功":
            assert_rl.assert_login_success(self, expect)
            self.tearDownClass()
            self.setUpClass()
        else:
            assert_rl.assert_login_error(self, expect)